// const { default: Swiper } = require("swiper");
let dom = require("../../utils/dom.js");
let https = require("../../utils/https.js");
require("../../assets/css/index.less");

// 2.引入当前样式表
require("../../assets/fonts/iconfont.css");
require("./home.less");

require("../../assets/lib/swiper/swiper-bundle.min.css");
import Swiper from "../../assets/lib/swiper/swiper-bundle.min.js";
dom.ready(function () {
  function getInfo() {
    https.get("/api/user/info", (res) => {
      console.log("res");
      if (res.errno == 0) {
        let { ranking, clockCount, badges } = res.data;

        dom.$("#rankText").innerHTML = ranking;
        dom.$("#clockText").innerHTML = clockCount;
        dom.$("#badgesText").innerHTML = badges;
      }

      console.log(res);
    });
  }
  function getClockInfo() {
    https.get("/api/user/clockInInfo", (res) => {
      if (res.errno == 0) {
        console.log(res.data.isClockIn, "+++++++");
        dom.$("#clockbtn").innerHTML = res.data.isClockIn
          ? "已经打卡了"
          : "今日打卡";
        dom.$("#clockText").innerHTML = res.data.clockCount;
      }
    });
  }
  getClockInfo();
  dom.addEvent("#clockbtn", function () {
    getClockInfo();
    https.post("/api/user/clockIn", {}, (res) => {
      if (res.errno == 0) {
        alert("今日已打卡");
        getClockInfo();
        getInfo();
      } else {
        alert(res.message);
      }
    });
  });
  // dom.$("#clockbtn").addEventListener("click", function () {});
  getInfo();
  new Swiper(".swiper", {
    autoplay: true,
    loop: true,
    pagination: {
      el: ".swiper-pagination",
    },
  });
});
dom.createFoot(0);
